//
//  VIPSignalingModel.m
//  TTProduct
//
//  Created by My mac on 2018/8/20.
//  Copyright © 2018年 TTProduct. All rights reserved.
//

#import "VIPSignalingModel.h"
#import "VIPPCH.h"

@implementation VIPSignalingModel

- (NSString *)opVersion {
    return AppLiveVideoVersion;
}

- (NSString *)opClientVersion {
    return AppVersion;
}

- (NSString *)platform {
    return @"Mac";
}

- (NSString *)msgID {
    if (_msgID.length == 0) {
        _msgID = [[NSUUID UUID] UUIDString];
    }
    return _msgID;
}

+ (instancetype)responseMessage:(NSString *)msg account:(NSString *)account {
    [VIPWrite writeLogWithFormat:@"%s - account:%@, msg: %@", __func__, account, msg];
    VIPSignalingModel *responseModel = [VIPSignalingModel mj_objectWithKeyValues:msg];
    if([responseModel.opType1 isEqualToString:OPTION_TYPE1_CLASS_EXCITATION]) {
        NSData *jsonData = [responseModel.opParam1.opParam2 dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData
                                                             options:NSJSONReadingMutableContainers
                                                               error:nil];
        NSArray *excitationUid = json[@"ExcitationUid"];
        NSString *giftID = [NSString stringWithFormat:@"%@", json[@"GiftID"]];
        NSInteger msgType = [json[@"MsgType"] integerValue];
        NSInteger type = [json[@"type"] integerValue];
        NSArray *data = json[@"data"];
        
        responseModel.opParam1.msgType = msgType;
        responseModel.opParam1.excitationUid = excitationUid;
        responseModel.opParam1.giftID = giftID;
        responseModel.opParam1.type = type;
        responseModel.opParam1.data = data;
        return responseModel;
    }
    
    NSData *jsonData = [msg dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:nil];
    if([responseModel.opType1 isEqualToString:OPTION_TYPE1_MICROPHONE_REQUEST] ||
       [responseModel.opType1 isEqualToString:OPTION_TYPE1_BRUSH_REQUEST]) {
        responseModel.opParam1.opParam2 = dic[@"opParam1"][@"opParam2"];
        responseModel.opParam1.opJsonParam2 = dic[@"opParam1"][@"opParam2"];
    }
    
    return responseModel;
}

@end


@implementation VIPWinSubSignalingModel

@end
